package main

import (
	"encoding/json"
	"fmt"
	"os"
	"strings"
)

func main() {
	//doDnsLocalFile()
	doBnbJson()
	//sb := strings.Builder{}
	//	dataGet233(&sb)

	//saveErr := os.WriteFile("web_dns_id.txt", []byte(sb.String()), 0600)
	//if saveErr != nil {
	//	panic(saveErr)
	//}

}
func doUrl() {
	sb := strings.Builder{}
	bd, err := os.ReadFile("bnb\\web_dns_id.txt")
	if err != nil {
		panic(err)
	}
	arrgs := strings.Split(string(bd), "\n")
	for i, iv2 := range arrgs {
		fmt.Println(i, iv2)
		//dataGetAppend(iv2, &sb)
	}
	saveErr := os.WriteFile("global_dns_001.txt", []byte(sb.String()), 0600)
	if saveErr != nil {
		panic(saveErr)
	}
}
func doDnsLocalFile() {
	sb := strings.Builder{}
	bd, err := os.ReadFile("global_dns_001.txt")
	if err != nil {
		panic(err)
	}
	arrgs := strings.Split(string(bd), "class=\"name_r r\"><a href=\"")
	for i, iv2 := range arrgs {
		//fmt.Println(i, iv2)
		if iv2[:4] == "http" {
			tmpUrl := iv2[:strings.Index(iv2, "\"")]
			if strings.Index(tmpUrl, "?") == -1 && strings.Index(tmpUrl, "click-") == -1 && strings.Index(tmpUrl, "/click") == -1 {
				fmt.Println(i, tmpUrl)
				sb.WriteString(tmpUrl)
				sb.WriteRune('\n')
			}
		}
	}
	saveErr := os.WriteFile("global_dns_001_url_02.txt", []byte(sb.String()), 0600)
	if saveErr != nil {
		panic(saveErr)
	}
}

type BnbJson struct {
	Name        string `json:"name"`
	Cost        string `json:"cost"`
	Expire      int    `json:"expire"`
	Label       string `json:"label"`
	Owner       string `json:"owner"`
	BlockNumber int    `json:"blockNumber"`
	Tx          string `json:"tx"`
}

func doBnbJson() {
	bd, err := os.ReadFile("bnb\\bnb.json")
	if err != nil {
		panic(err)
	}
	var jsonBnb = make([]BnbJson, 0)
	errL := json.Unmarshal(bd, &jsonBnb)
	if errL != nil {
		panic(err)
	}
	mapok := make(map[string]int, 0)
	for i := 0; i < len(jsonBnb); i++ {
		mapok[jsonBnb[i].Name] = 1
		//fmt.Println(i, jsonBnb[i].Name)
	}
	fmt.Println("已注册数量:", len(mapok))
	bd2, err2 := os.ReadFile("bnb\\bnb_input.txt")
	if err2 != nil {
		panic(err2)
	}
	sbRest := strings.Builder{}
	rows := strings.Split(string(bd2), "\n")
	cnt := 0
	for _, i2 := range rows {
		val := strings.ReplaceAll(i2, "\r", "")
		if _, ok := mapok[val]; !ok {
			cnt++
			sbRest.WriteString(i2)
			sbRest.WriteRune('\n')
		}
	}
	saveErr := os.WriteFile("dns_ok.txt", []byte(sbRest.String()), 0600)
	if saveErr != nil {
		panic(saveErr)
	}
	fmt.Printf("找到:%d个可用，保存到dns_ok.txt文件中", cnt)
}
